home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 462 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.4 KB  |  84 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Proposal: Reconcile Inheritance and Inlining
  5. Date: 23 Feb 1996 17:12:35 GMT
  6. Organization: FakultΣt fⁿr Mathematik und Informatik
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4gkscd$8rl@news.BelWue.DE>
  9. References: <4gkas9$4o84@news-s01.ny.us.ibm.net>
  10. Reply-To: dietmar.kuehl@uni-konstanz.de
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. Content-Type: text
  13. X-Nntp-Posting-Host: uzwil.informatik.uni-konstanz.de
  14. X-Newsreader: TIN [version 1.2 PL2]
  15. Content-Length: 1466
  16. X-Lines: 58
  17. Originator: clamage@taumet
  18.  
  19. Hi,
  20.  
  21. Rich Hickey (hickeyr@ibm.net) wrote:
  22. [Explanation of the proposal removed]
  23.  
  24. : class B{
  25. : public:
  26. :    virtual int foo()const=0;
  27. :    //...
  28. : };
  29.  
  30. : explicit class D:public B{
  31. : public:
  32. :   int foo()const{return data;}
  33. :   //...
  34. : private:
  35. :   int data;
  36. : };
  37.  
  38. : void fred(const D &d)
  39. :    {
  40. :    d.foo();  //as if d.D::foo(); - inlined
  41. :    }
  42.  
  43. : void ethel(const B &b)
  44. :   {
  45. :   b.foo();    //even if b is a D, virtual function call (as always)
  46. :   }
  47.  
  48.  
  49. : It cannot be otherwise accomplished in the language, i.e. it requires an extension.
  50.  
  51. I think it is easy to accomplish the thing you want to do in the language:
  52.  
  53.   class E: public B {
  54.   public:
  55.     int foo_inline() const { return data; }
  56.     int foo() const        { foo_inline(); }
  57.   private:
  58.     int data;
  59.   };
  60.  
  61.   void foo(E const &e)
  62.   {
  63.     e.foo_inline(); // inline. Note that you know exactly the type of 'e'
  64.     e.foo();        // virtual as ever
  65.   }
  66.  
  67. Although I agree with you that your proposal is nicer to use, your
  68. claim that it cannot be implemented in the language is wrong...
  69. However, it would be nice to have a simple possibility to close a class
  70. for further derivation (I know that it is possible using a friend and a
  71. virutal base class but I think that this could even impose some runtime
  72. penalty due to the representation of virtual bases).
  73. --
  74. dietmar.kuehl@uni-konstanz.de
  75. http://www.informatik.uni-konstanz.de/~kuehl
  76. I am a realistic optimist - that's why I appear to be slightly pessimistic
  77.  
  78. [ To submit articles: Try just posting with your newsreader.
  79.               If that fails, use mailto:std-c++@ncar.ucar.edu
  80.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  81.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  82.   Comments? mailto:std-c++-request@ncar.ucar.edu
  83. ]
  84.